home *** CD-ROM | disk | FTP | other *** search
/ Acorn User: China / Acorn User China CD-ROM (UK) (Disc B) / Acorn User China CD-ROM (UK) (Disc B).bin / STUTTGART / FROMUTS / UNIXLIB37B / clib_h_stdio < prev    next >
Encoding:
Text File  |  1992-08-19  |  4.2 KB  |  184 lines

  1. /* stdio.h (c) Copyright 1990 H.Rogers */
  2.  
  3. #ifndef __STDIO_H
  4. #define __STDIO_H
  5.  
  6. #ifndef __STDARG_H
  7. #include <stdarg.h>
  8. #endif
  9.  
  10. #ifndef __SYS_TYPES_H
  11. #include "sys/types.h"
  12. #endif
  13.  
  14.  
  15. #define OPEN_MAX    64
  16.  
  17. #define FOPEN_MAX    64
  18. #define FILENAME_MAX    252
  19.  
  20. #define BUFSIZ        1024
  21. #define EOF        (-1)
  22.  
  23. #define SEEK_SET    0
  24. #define SEEK_CUR    1
  25. #define SEEK_END    2
  26.  
  27. typedef struct __iobuf
  28.   {
  29.   unsigned char *i_ptr;
  30.   unsigned char *i_base;
  31.   int        i_cnt;
  32.   unsigned char *o_ptr;
  33.   unsigned char *o_base;
  34.   int        o_cnt;
  35.   int        flag;
  36.   int        fd;
  37.   fpos_t    pos;
  38.   int        bufsiz;
  39.   } __FILE;
  40.  
  41. #define FILE __FILE
  42.  
  43. extern    FILE        __iob[FOPEN_MAX];
  44.  
  45. #define stdin        (&__iob[0])
  46. #define stdout        (&__iob[1])
  47. #define stderr        (&__iob[2])
  48.  
  49. #define _IOOMASK    0000003
  50.  
  51. #define _IOREAD     0000001
  52. #define _IOWRITE    0000002
  53. #define _IOAPPEND    0000004
  54.  
  55. #define _IOBF        0000070
  56.  
  57. #define _IONBF        0000010
  58. #define _IOLBF        0000020
  59. #define _IOFBF        0000040
  60.  
  61. #define _IOEOF        0000100
  62. #define _IOERR        0000200
  63.  
  64. #define _IOTTY        0000400
  65. #define _IOPIPE     0001000
  66.  
  67. #define feof(f)     ((f)->flag & _IOEOF)
  68. #define ferror(f)    ((f)->flag & _IOERR)
  69. #define fileno(f)    ((f)->fd)
  70. #define fisatty(f)    ((f)->flag & _IOTTY)
  71. #define fispipe(f)    ((f)->flag & _IOPIPE)
  72. #define fisopen(f)    ((f)->flag & (_IOREAD|_IOWRITE))
  73.  
  74. #define clearerr(f)    (void)((f)->flag &= (~(_IOEOF|_IOERR)))
  75.  
  76. extern    int    (feof)(FILE *);
  77. extern    int    (ferror)(FILE *);
  78. extern    int    (fileno)(FILE *);
  79. extern    int    (fisatty)(FILE *);
  80. extern    int    (fisopen)(FILE *);
  81.  
  82. extern    void    (clearerr)(FILE *);
  83.  
  84. extern    void    perror(const char *);
  85.  
  86. extern    void    __stdioinit(void);    /* initialise stdin,stdout & stderr */
  87. extern    void    __stdioexit(void);    /* close streams & delete tmpfile() */
  88.  
  89. extern    int    __filbuf(FILE *);    /* fill buffer */
  90. extern    int    __flsbuf(int,FILE *);    /* flush buffer */
  91.  
  92. extern    char    *__null;        /* null pointer output */
  93.  
  94. extern    FILE    *fopen(const char *,const char *);
  95. extern    FILE    *freopen(const char *,const char *,FILE *);
  96. extern    FILE    *fdopen(int,const char *);
  97. extern    int    fclose(FILE *);
  98. extern    int    fflush(FILE *);
  99.  
  100. extern    FILE    *popen(const char *,const char *);
  101. extern    int    pclose(FILE *);
  102.  
  103. extern    int    __fread(FILE *,char *,int);
  104. extern    int    __fwrite(FILE *,char *,int);
  105.  
  106. extern    size_t    fread(void *,size_t,size_t,FILE *);
  107. extern    size_t    fwrite(const void *,size_t,size_t,FILE *);
  108.  
  109. extern    void    setbuf(FILE *,char *);
  110. extern    int    setvbuf(FILE *,char *,int,size_t);
  111.  
  112. extern    int    ungetc(int,FILE *);
  113.  
  114. extern    int    fgetpos(FILE *,fpos_t *);
  115. extern    int    fsetpos(FILE *,const fpos_t *);
  116.  
  117. extern    int    fseek(FILE *,long,int);
  118. extern    long    ftell(FILE *);
  119. extern    void    rewind(FILE *);
  120.  
  121. #define getc(f) \
  122.     ((--((f)->i_cnt) >= 0 ? *((f)->i_ptr)++ : __filbuf(f)))
  123. #define getchar()    getc(stdin)
  124.  
  125. extern    int    fgetc(FILE *);
  126. extern    int    (getc)(FILE *);
  127. extern    int    (getchar)(void);
  128. extern    int    getw(FILE *);
  129.  
  130. #define putc(c,f) \
  131.     (((((f)->flag) & _IOLBF) && (c) == '\n') ? __flsbuf(c,f) : \
  132.     ((--((f)->o_cnt) > 0 ? (*((f)->o_ptr)++ = (c)) : __flsbuf(c,f))))
  133. #define putchar(c)    putc(c,stdout)
  134.  
  135. extern    int    fputc(int,FILE *);
  136. extern    int    (putc)(int,FILE *);
  137. extern    int    (putchar)(int);
  138. extern    int    putw(int,FILE *);
  139.  
  140. extern    char    *fgets(char *,int,FILE *);
  141. extern    char    *gets(char *);
  142.  
  143. extern    int    fputs(const char *,FILE *);
  144. extern    int    puts(const char *);
  145.  
  146. /* formatted I/O */
  147.  
  148. extern    int    __printf(char *,const char *,va_list);
  149. extern    int    __scanf(FILE *,const char *,va_list,int *);
  150.  
  151. extern    char    *__pbuf;    /* buffer for printf */
  152. extern    char    *__sbuf;    /* buffer for scanf */
  153.  
  154. extern    int    vsprintf(char *,const char *,va_list);
  155. extern    int    vfprintf(FILE *,const char *,va_list);
  156. extern    int    vprintf(const char *,va_list);
  157. extern    int    sprintf(char *,const char *,...);
  158. extern    int    fprintf(FILE *,const char *,...);
  159. extern    int    printf(const char *,...);
  160.  
  161. extern    int    sscanf(const char *,const char *,...);
  162. extern    int    fscanf(FILE *,const char *,...);
  163. extern    int    scanf(const char *,...);
  164.  
  165. #define P_tmpdir    "/tmp"
  166. #define L_tmpnam    255
  167. #define TMP_MAX     0x100
  168.  
  169. extern    int    remove(const char *);
  170. extern    int    rename(const char *,const char *);
  171. extern    FILE    *tmpfile(void);
  172. extern    char    *tmpnam(char *);
  173.  
  174. extern    char    *mktemp(char *);
  175. extern    int    mkstemp(char *);
  176.  
  177. extern    FILE        *__tmpf;
  178. extern    char        __tmpn[L_tmpnam + 1];
  179. extern    unsigned int    __tmpcnt;
  180.  
  181. #define __STDIOLIB__ static void __stdiolib(void) { __stdioinit(); }
  182.  
  183. #endif
  184.